package com.kcl.dfss.adapter;

import java.util.HashMap;
import java.util.List;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.kcl.dfss.R;

@SuppressLint("ViewHolder")
public class DeviceAdapter extends BaseAdapter {

	private List<HashMap<String, String>> list;
	private Context context;
	private int type[];
	
	public DeviceAdapter(List<HashMap<String, String>> list,Context context,int type[]) {
		this.list = list;
		this.context = context;
		this.type = type;
	}
	
	@Override
	public int getCount() {
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@SuppressLint("ViewHolder")
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		LayoutInflater mInflater = LayoutInflater.from(context);
		View view = null;
		switch(type[position]){
		case 0:
			view = mInflater.inflate(R.layout.device_item1, null);
			String content = list.get(position).get("data");
			String items[] = content.split(",");
			TextView text_machine = (TextView) view.findViewById(R.id.text_machine);
			TextView text_machinename = (TextView) view.findViewById(R.id.text_machinename);
			ImageView image_machine = (ImageView) view.findViewById(R.id.image_machine);
			image_machine.setImageResource(R.drawable.arrow_right);
			text_machine.setText(items[0]);
			text_machinename.setText(items[1]);
			break;
		case 1:
			view = mInflater.inflate(R.layout.device_item2, null);
			String content1 = list.get(position).get("data");
			String items1[] = content1.split(",");
			TextView text_deviceID = (TextView) view.findViewById(R.id.text_deviceID);
			TextView text_deviceno = (TextView) view.findViewById(R.id.text_deviceno);
			text_deviceID.setText(items1[0]);
			text_deviceno.setText(items1[1]);
			break;
		case 2:
			view = mInflater.inflate(R.layout.device_item3, null);
			String content2 = list.get(position).get("data");
			TextView text_rom = (TextView) view.findViewById(R.id.text_rom);
			text_rom.setText(content2);
			break;
		}

		return view;
	}

}
